﻿using System.Web.Routing;

namespace CodeContrib.Web.Routing
{
	public class LowercaseRoute : Route
	{
		public LowercaseRoute(string url, IRouteHandler routeHandler) : base(url, routeHandler)
		{
			Constraints = new RouteValueDictionary();
			DataTokens = new RouteValueDictionary();
			Defaults = new RouteValueDictionary();
		}

		public LowercaseRoute(string url, RouteValueDictionary defaults, IRouteHandler routeHandler) : base(url, defaults, routeHandler)
		{
			Constraints = new RouteValueDictionary();
			DataTokens = new RouteValueDictionary();
		}

		public LowercaseRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler routeHandler) : base(url, defaults, constraints, routeHandler)
		{
			DataTokens = new RouteValueDictionary();
		}

		public LowercaseRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens, IRouteHandler routeHandler) : base(url, defaults, constraints, dataTokens, routeHandler)
		{
		}

		public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
		{
			var path = base.GetVirtualPath(requestContext, values);

			if (path != null)
			{
				path.VirtualPath = path.VirtualPath.ToLowerInvariant();
			}

			return path;
		}
	}
}